public class Demo12 {
public static void main(String[] args) {
    //获取main线程的引用
    Thread mainThread=Thread.currentThread();
   
    Thread t=new Thread(()->{
        // 让t线程阻塞等待main线程
        try {
            System.out.println("t线程等待之前");
            mainThread.join();
            System.out.println("t线程等待之后");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    t.start();
    for(int i =0;i<10;i++){
        System.out.println("hello main");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
}
